package com.mysiteforme.admin.service.impl.publish;

import com.baomidou.mybatisplus.plugins.Page;
import com.mysiteforme.admin.entity.publish.ElectricityOrder;
import com.mysiteforme.admin.dao.publish.ElectricityOrderDao;
import com.mysiteforme.admin.service.publish.ElectricityOrderService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author wangl
 * @since 2019-09-18
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ElectricityOrderServiceImpl extends ServiceImpl<ElectricityOrderDao, ElectricityOrder> implements ElectricityOrderService {

    @Autowired
    private ElectricityOrderDao electricityOrderDao;

    @Override
    public Map statistics() {
        Map map = electricityOrderDao.statistics();
        if(map == null || map.size() < 1){
            map = new HashMap();
            map.put("amoyValue",0);
            map.put("amoyPrice",0);
            map.put("num",0);
        }
        return map;
    }

    @Override
    public Page<ElectricityOrder> selectOrderList(Map map) {
        int _page = Integer.valueOf(map.get("page").toString());
        int _limit = Integer.valueOf(map.get("limit").toString());
        List<ElectricityOrder> list = electricityOrderDao.selectOrderList(map);
        int count = electricityOrderDao.selectSupplyCount(map);
        Page<ElectricityOrder> page = new Page<>();
        page.setRecords(list);
        page.setCurrent(_page);
        page.setSize(_limit);
        page.setTotal(count);
        return page;
    }
}
